<template>
  <div style="position: relative; padding: 0 15px" @click="toggleClick">
    <svg
      :class="{ 'is-active': isActive }"
      class="hamburger"
      viewBox="0 0 1024 1024"
      xmlns="http://www.w3.org/2000/svg"
      width="64"
      height="64"
    >
      <path
        d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM142.4 642.1L298.7 519a8.84 8.84 0 0 0 0-13.9L142.4 381.9c-5.8-4.6-14.4-.5-14.4 6.9v246.3a8.9 8.9 0 0 0 14.4 7z"
      />
    </svg>
    <div ref="dot" class="notification-dot" v-show="count != 0">
      <span class="dot-text">{{ count }}</span>
      <!-- 修改数字 -->
    </div>
  </div>
</template>

<script>
export default {
  name: "Hamburger",
  props: {
    isActive: {
      type: Boolean,
      default: false,
    },
    count: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  methods: {
    toggleClick() {
      this.$emit("toggleClick");
    },
  },
  watch: {
    count(newValue) {
      let str = new String(newValue);
      if (str.length > 1) {
        this.$refs.dot.style.width = `${str.length * 7}px`;
      }
    },
  },
  mounted() {
    let str = new String(this.count);
    if (str.length > 1) {
      this.$refs.dot.style.width = `${str.length * 7}px`;
    }
  },
};
</script>

<style scoped>
.hamburger {
  display: inline-block;
  vertical-align: middle;
  width: 20px;
  height: 20px;
}

.hamburger.is-active {
  transform: rotate(180deg);
}

.notification-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 14px; /* 调整宽度 */
  height: 14px; /* 调整高度 */
  background-color: red;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dot-text {
  color: white;
  font-size: 10px; /* 调整字体大小 */
  font-weight: bold;
}
</style>
